// pages/crossOrder/crossOrder.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navLists:[
      {
        name: "待审核",
        id:0
      },
      {
        name: "待发货",
        id: 1
      },
      {
        name: "待收货",
        id: 2
      },
      {
        name: "已完成",
        id: 3
      },
    ],
    current:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    this.setData({
      userInfo: wx.getStorageSync("userInfo"),
      imageUrl: app.globalData.imageUrl
    })
    wx.getSystemInfo({//获取滑块的高宽
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
    getOrderForm(that,0);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
  getOrderList:function(e){
    this.setData({
      current:e.target.id
    })
   
    getOrderForm(this, e.target.dataset.id);
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
  deleteOrder:function(e){
    deleteOrderForm(this,e.target.id)
  },
  getlogistic:function(e){
    getlogistics(this, e.target.dataset.trackingnum)
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
  , cancelOrder:function(e){//取消订单

  },
  sureReceiving:function(e){
    var that=this;
    wx.showModal({
      title: '提示',
      content: '是否确认收货',
      showCancel: true,
      success: function (res) {
        if (res.confirm) {
          Receiving(that,e)
        }
      }
    })
  }
 /* , sureReceiving: function (e) {//确认收货
  var that=this;
    wx.request({
      url: app.globalData.allUrl + "/productaAction/receiving",
      data: {
        orderFormId:e.target.id
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        console.log(res.data);
        if(res.data==true){
          getOrderForm(that, 2)
          setTimeout(function(){
            wx.navigateTo({
              url: '../../pages/shopManage/shopManage',
            })
          },1500)        
        }
      }
    })
  }*/
  , logistics: function (e) {//物流

  },
})


function getOrderForm(that,_id){
  wx.request({
    url: app.globalData.allUrl + "/orderFormAction/getOrderFormByStatusAndType",
    data: {
      userid: parseInt( wx.getStorageSync('userid')),//用户唯一ID
      status: _id ,//订单状态ID（1-5）,
      typeId:2
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
       console.log(res.data);
       if(!res.data||res.data.length>200){
         return
       }
      that.setData({
        allOrderForm:res.data,
      })
    }
  })
}
function deleteOrderForm(that, _id) {
  console.log(_id)
  wx.request({
    url: app.globalData.allUrl + "/orderFormAction/updateOrderStatus",
    data: {
     // userid: parseInt(wx.getStorageSync('userid')) ,//用户唯一ID
      status: 8 ,
     // typeId: 2,
      Id: _id//订单状态ID（1-5）
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      console.log(res.data);
      getOrderForm(that,3)
    }
  })
}


function getlogistics(that,_id){
  wx.navigateTo({
    url: '../../pages/logistics/logistics?id=' + _id,
  })
  console.log(_id)

}


function Receiving(that,e){
  wx.request({
    url: app.globalData.allUrl + "/productaAction/receiving",
    data: {
      orderFormId: e.target.id
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.data == true) {
        getOrderForm(that, 2)
        setTimeout(function () {
          wx.navigateTo({
            url: '../../pages/shopManage/shopManage',
          })
        }, 1500)
      }
    }
  })
}